
{php include wl_template('common/header');}
{if $config['base']['meiqia']>0}
<script type='text/javascript'>
    (function(m, ei, q, i, a, j, s) {
        m[a] = m[a] || function() {
            (m[a].a = m[a].a || []).push(arguments)
        };
        j = ei.createElement(q),
            s = ei.getElementsByTagName(q)[0];
        j.async = true;
        j.charset = 'UTF-8';
        j.src = i + '?v=' + new Date().getUTCDate();
        s.parentNode.insertBefore(j, s);
    })(window, document, 'script', '//static.meiqia.com/dist/meiqia.js', '_MEIQIA');
    _MEIQIA('entId', {$config['base']['meiqia']});
	</script>
	{/if}
<style>
	.link-rule p {text-indent:2em;}
  .tablerow {margin-bottom: 5px;}
  .buyimg {display:table-cell;width:45%;}
  .buyimg img{width:40px;height:40px;border-radius:20px;}
  .buyprice {width: 10%;height: 100%;display: table-cell;line-height: 40px;text-align: center;padding-right: 10px;}
  .buydes {  width: 45%;height: 100%;display: table-cell;position: relative;top: 7.5px;}
  .buyplus {  float: left;width: 35px;text-align: center;height: 25px;border-radius: 12.5px;background-color:  #6fbfd8;color: white;}
  .buynum {  width: 25px;height: 25px;left: 0px;right: 0px;margin: auto;position: absolute;text-align: center;line-height: 25px;top: 0;}
  .buyminus {  text-align: center;float: right;width: 35px;height: 25px;border-radius: 12.5px;background-color: hsl(194, 57%, 64%);color: white;}
  .key{display:none;}
  #guigeDetail {width: 90%;margin: auto;text-align: center;overflow: scroll;bottom: 65px;position: absolute;left: 5%;top: 65px;}
  .guigeSelect {text-align: left;padding-left: 10px;font-size: 20px;display: block;clear: both;}
  #guigeDetail li {margin-left: 8px;float: left;padding: 5px 5px 5px 5px;height: auto;color: #999;border: 1px solid #e4e4e4;}
  .guigeactive {  background-color: hsl(354, 91%, 73%)!important;color: white!important;}
  .toast{z-index:1000000000!important;}
  .number{display:none!important;}
		.link-rule{
		height:100%;
		width:100%;
		background-color:
		rgba(128,128,128,0.5);
		position:fixed;top:0px;
		left:0px;
		z-index:10000;
	}
	.link-rule>div{
		text-align:center;
		position:absolute;
		top:0;
		bottom:0;
		left:8px;
		right:8px;
		margin-top:auto;
		margin-bottom:auto;
		height:85%;
		background-color:white;
		border-radius:8px;
	}
	.link-rule>div>div:first-child{
		 font-weight:bold;
		 background-color:#ececec;
		 font-size:20px;
		 line-height:40px;
		 border-radius:8px 8px 0 0;
		 height:40px;
	}
	.link-rule>div div:nth-child(2){
		 text-align:left;
		 position:absolute;
		 top:48px;
		 bottom:45px;
		 left:19px;
		 right:19px;
		 overflow:scroll;
	}
	.link-rule>div div:last-child{
		 position:absolute;
		 left:0px;
		 right:0px;
		 width:150px;
		 height:30px;
		 bottom:5px;
		 background-color:#0894ec;
		 color:white;
		 font-size:18px;
		 margin-left:auto;
		 margin-right:auto;
		 line-height:30px;
		 border-radius:5px;
	}
	.noactive {
		background-color: gray;
	}
	#goodsid, #goodsweight, #goodsgnum, #goodsguige { display: none;}
	#pricedown {   
		display: block;
		width: 40px;
		height: 40px;
		background-color: hsl(194, 57%, 64%);
		color: hsl(0, 0%, 100%);
		line-height: 15px;
		text-align: center;
		border-radius: 20px;
		padding-top: 5px;
		font-size: 12px;
		right: 20px;
		top: 35px;
		position: absolute;
	}
	#returnBack {
		width: 40px;
		height: 40px;
		border-radius: 20px;
		background: linear-gradient(90deg,transparent 1px, hsla(0, 0%, 50%, 0.7) 0);
		position: absolute;
		left: 20px;
		top: 20px;
		z-index: 3;
		color: white;
		text-align: center;
		line-height: 16px;
		padding-top: 4px;
		font-weight: bold;
		font-size: 12px;
	}
	#returnBack::before {
		content: '';
		position: absolute;
		left: -3px;
		top: 16px;
		height: 8px;
		width: 8px;
		background: linear-gradient(45deg,hsla(0, 0%, 50%,0.7) 50%, transparent 0);
		transform: rotate(45deg);
		-webkit-transform:rotate(45deg);
	}
</style>

<span id="goodsid">{$goods['id']}</span>
<span id="goodsweight">{$goods['weight']}</span>
<span id="goodsgnum">{$goods['gnum']}</span>
<span id="isshow">{$goods['isshow']}</span>
<span id="goodsguige">{$goods['hasoption']}</span>
<img style="display:none;" src="{$goods['gimg']}">
<div class="page-group">
    <div class="page page-current" id="page-goods-detail">
		<div id="returnBack">
		<!--<svg width="40px" height="40px" viewBox="0 0 100 100"
		 xmlns="http://www.w3.org/2000/svg">
		 <path d="M65 25 25 50 65 75" style="stroke-width:8;stroke: white;fill:none;stroke-linejoin:round"/>
		 </svg>-->
		 返回<br/>商城
	</div>
    	<div class="content">
    		<div class="dt_detail">
			    <section class="detail_main">
				{if  !empty($advs)}
			        <div class="sliderImage">
			            <div class="images" id="sliderImg" style="visibility: visible;">
			            	<ul>
			            		{loop $advs $adv}
			            		<li><img src="{php echo tomedia($adv['thumb']);}" style='width:100%;'></li>
			            		{/loop}
							</ul>
			            </div>
			            <div class="images_num" id="sliderNum">
			            	{php $slideNum = 1;}
					    	{loop $advs $adv}
					        <span{if $slideNum == 1} class="curr"{/if}></span>
					        {php $slideNum++;}
					    	{/loop}
			            </div>  
			        </div>
					{/if}
			    	<div class="productInfo" style="position:relative;">
					
					<div class="salesVolume" style="display: block;padding-top: 10px;height:40px"><span id="goodsprice" style="float: left;font-size:26px;color:#6fbfd8;">￥{$goods['oprice']}</span><span style="float: left;line-height:250%;
    text-decoration: line-through;">{if $config['base']['ismarketprice']==0}市场价：￥{$goods['mprice']}{/if}</span><span style="line-height:250%;
    ;text-align:right;">{if $config['base']['issell']==0}已售：{$goods['salenum']}{/if}</span></div>
			    		<h2 id="goodstitle" style="padding-top: 10px;margin-right:20%;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;">{$goods['gname']}</h2>
			    		<span id="pricedown" {if $goods['isdownjia']==0}style="display:none;"{/if}>降价<br/>通知</span>
			    		<div class="editor" >{$goods['goodsdesc']}</div>
			    	</div>
					<!--<div style="padding-left:10px;color:#888;background-color:white;font-size:0.8em;">商品确认收货后可获得10086积分</div>-->
			    	<div class="progressOuter noShow"><span class="suc_tuan">已成团</span>
			    	<div class="progress"><div class="percent"></div></div><span class="total_tuan">共团</span></div>
			    	
			    	<script>
					    $(function() {
					        new Swipe($('#sliderImg')[0], {
					            speed:500,
					            auto:3000,
					            callback: function(){
					                var lis = $("#sliderNum").children();
					                lis.removeClass("curr").eq(this.index).addClass("curr");
					            }
					        });
					    });
					</script>
			    </section>
			    <section class="goBuy" data-people="3" data-times="10" data_acttype="0" data_coupon="0" data_dealtype="" style="display: block;">
			        <div class="btns" style="display: none;">
			            <div class="group_btn" id="buyGroup"><span class="price"><em>8.9元</em>/{$goods['unit']}</span><span class="colline"></span><span class="count">3人团&gt;</span></div>
			           <div class="single_btn" id="buySingle"><span class="price"><em>10.9元</em>/{$goods['unit']}</span><span class="colline"></span><span class="count">单独购买&gt;</span></div>
			        </div>
					
			        {if $goods['isshow']==3}
			        <div class="ico_end"></div>
			        {elseif $goods['isshow']==2}
			        <div class="ico_countdown"></div>
			        {/if}
			        <div class="tuan_btn" id="buyNow"><span>立即参团</span><span><i class="rowline"></i><em>8.9元</em>/{$goods['unit']}</span></div>
			        <div class="goIndexBtn">去首页逛逛吧</div>
			        <p class="activityTip"></p>
			    </section>
			    <div class="space" style="display: none;"></div>
			    
			   
		      
		        
			    
			</div>
			
	        <div class="section_body info_detail">
		        <div>
	            <div id="div_nav_fixed" style="display:none">
	                <div id="div_nav" class="div_nav">
	                    <ul class="boxx" style="padding-left: 0px;">
	                    	<li>
	                            <a onclick="exchange(1);" data-idx="1" class="sp on" id="shangpin1">图文详情</a>
	                        </li>
	                        <li>
	                            <a onclick="exchange(0);" data-idx="0" class="sp" id="shangpin0">商品属性</a>
	                        </li>
	                    </ul>
	                </div>
	            </div>
	            <div id="div_sections" class="div_sections">
	                <section class="section_specification">
	                	{loop $params $p}
	                    <dl>
	                        <div>
	                            <dd><label>{$p['title']}</label><label>{$p['value']}</label></dd>
	                        </div>
	                    </dl>
	                    {/loop}
	                </section>
	                <section class="section_detail on" data-role="widget" data-widget="img_prev_view">
	                    <div id="description" class="J_DetailSection tshop-psm tshop-psm-bdetaildes" style="margin:0px;padding:0px;">
	                        <div class="ke-post" id="productInfott" style="margin:10px 0px 0px;padding:0px;font-size:14px;font-family:tahoma, arial, 宋体, sans-serif;">
	                            
	                        </div>
	                    </div>
	                </section>
	            </div>
		        </div>
		    </div>
			<div style="height:65px;"></div>
			<input type="hidden" name="times" id="times" value="{$times}" />
		 	<input type="hidden" name="one_limit" id="one_limit" value="{$goods['one_limit']}" />
		 	<input type="hidden" name="many_limit" id="many_limit" value="{$goods['many_limit']}" />
	 	
			
    	</div>
	    {if $goods['hasoption']==1||$goods['one_limit']>1}
	    	{php include wl_template('goods/goods_option2');}
	    {/if}
		<!--<footer class="footer" style="z-index: 1!important;height: 50px;">
	        <nav>
	            <ul>
				
	                <li style="width: 20%;"><a href="{php echo app_url('goods/list')}" id="gohome" class="nav-controller external"><img src="{TG_URL_ARES}images/icon_home.png" height="18px" width="19px"><br>首页</a></li>
	                {if $goods['isshow']==1}
					{if $goods['group_level_status']==2}
						<li class="group" style="color:white;"><a onclick='choose()' class="nav-controller"><i >￥{$goods['gprice']}</i>{$goods['groupnum']}人拼团</a></li>
						<li class="alone" style="color:white;"><a  style="color:white;" href="{php echo app_url('order/orderconfirm',array('groupnum'=>1));}" class="nav-controller external"><i >￥{$goods['oprice']}</i>单独购买</a></li>
	                	
					{elseif $goods['hasoption']==1||$goods['one_limit']>1}
						
	                	<li class="group" style="color:white;"><a onclick='choose(2)' class="nav-controller"><i >￥{$goods['gprice']}</i>{$goods['groupnum']}人拼团</a></li>
						<li class="alone"><a  style="color:white;" onclick='choose(1)' class="nav-controller"><i >￥{$goods['oprice']}</i>单独购买</a></li>
					{else}
						<li class="group" style="color:white;"><a onclick='bb(2)'  class="nav-controller"><i >￥{$goods['gprice']}</i>{$goods['groupnum']}人拼团</a></li>
						<li class="alone" style="color:white;"><a style="color:white;" onclick='bb(1)'  class="nav-controller"><i >￥{$goods['oprice']}</i>单独购买</a></li>
	                	
					{/if}
					{else}
					<li class="group" style="width: 80%;"><a href="{php echo app_url('goods/list')}" style="line-height: 40px;font-size: 16px;" class="nav-controller external">查看更多拼团商品</a></li>
					{/if}
	            </ul>
	        </nav>
	    </footer>-->
<div style="height:54px;width:90%;left:5%;position:fixed;z-index:186;background-color:transparent;bottom:10px;">
			<a id="gohome" class="home external {if $_GPC['ac']=='list'}cur{/if}" style="position:absolute;display: block;width: 70px;height: 50px;left:-8px;line-height: 46px;text-align: center;color:white;background-color:hsl(194, 57%, 64%);z-index:2;border-radius: 25px;border:2px solid white;" href="{php echo app_url('goods/list')}" onclick=""><i></i><img src="{TG_URL_ARES}images/111.png"  width="25px" height="25px" style="margin-top:-5px;"></a>
<div id="buycart" style="  position: absolute;height: 44px;border-radius: 15px;background-color: white;left: 0px;bottom: 10px;right: 0px;margin: auto;background-color: transparent;text-align: center;z-index: 1;">
<span style="background-color: hsl(194, 57%, 64%);color: white;position: relative;height: 50px;line-height: 46px;display: inline-block;padding-left: 45px;border-radius: 25px;padding-right: 10px;border: 2px solid white;">
  <img id="buycartimg" src="{TG_URL_ARES}images/buycart.jpg" width="44px" height="44px" style="  position: absolute;left: 1px;border-radius: 22px;top: 1px;">
  <div id="totalnum" style="display:none;height: 18px;border-radius: 9px;line-height: 18px;position: absolute;text-align: center;padding-left: 5px;padding-right: 5px;left: 18px;top:5px;font-size: 14px;color: white;background-color: red;">0</div>
  <span id="sumprice"></span>
<span>
</div>
	<a style="position:absolute;display: block;width: 70px;height: 50px;right:-8px;background-color:hsl(194, 57%, 64%);line-height: 46px;text-align: center;color:white;z-index:2;border-radius: 25px;border:2px solid white;" 
	   {if $goods['hasoption']==1||$goods['one_limit']>1}
	    	onclick="choose(2)"
	    {/if}
	{if $goods['hasoption'] < 1}
	    	onclick="plusNumber(this)"
	    {/if}		>
	<i></i><span>购买</span><img id="flyimg" style="position:absolute;left:20px; right:0;width:30px;height:30px;
	border-radius:50%;"></a>

</div>
	
</div>
	    <input type="hidden" id="buytype" value="" />
	    <input type="hidden" id="buytype2" value="{$goods['groupnum']}" />
	    <input type="hidden" id="optionid" name="optionid" value=""/>
	</div>
</div>

<div id="cartDetails" style="transition-duration:0.5s;transition-property:height opacity;opacity:1;transition-timing-function:ease-out;overflow:hidden;
position:fixed;top:0px;left:0px;width:100%;height:0%;background-color:rgba(0,0,0,0.5);z-index:100860;">
  <div style="  position: absolute;width: 90%;height: 85%;background-color: white;top: 5%;left: 5%;margin-bottom: auto;margin-top: auto;border-radius: 5px;box-shadow: 2px 2px 2px black;">
    <div style="  width: 80%;margin-left: 10%;height: 40px;font-size: 1.5em;line-height: 40px;color:#6fbfd8;text-align: center;border-bottom: 1px solid #eee;box-sizing: border-box;">您选择的商品</div>
	<div style="  border-bottom: 1px solid #f0f0f0;overflow: auto;position: absolute;left: 10%;right: 10%;top: 50px;bottom: 50px;">
	<div id="buycartDetails">		
	</div>
	</div>
	<div style="width:100%;height:40px;position:absolute;left:0;bottom:10px;">
	  <div id="continueBuy" style="width:30%;float:left;margin-left:2.5%;height:30px;background-color:#6fbfd8;color:white;line-height:30px;text-align:center;border-radius:3px;margin-top:10px;">继续选购</div>
	  <div  style="width:30%;float:left;margin-left:2.5%;height:30px;background-color:#6fbfd8;color:white;line-height:30px;text-align:center;border-radius:3px;margin-top:10px;" onclick="clearBuycart();">一键清除</div>
	  <div id="goPay" style="width:30%;float:left;margin-left:2.5%;height:30px;background-color:#6fbfd8;color:white;line-height:30px;text-align:center;border-radius:3px;margin-top:10px;" onclick="Buycart();">立即结算</div>
	</div>
  </div>
</div>

<script>
alert('deltal2');
	var buycart = document.getElementById( "buycart" );
	var urlclear = "{php echo app_url('goods/list/clear')}";
	var urladd = "{php echo app_url('goods/list/add')}";
	var urlRemove = "{php echo app_url('goods/list/remove')}";
	var urlweight = "{php echo app_url('goods/list/weight')}";
	var Buy = {};
	var User = JSON.parse(localStorage.getItem("user"))|| {};
	var GuigeSelect = {};
	var Guige = {};	
	var isPost = true;
	var gohome = document.getElementById("gohome");
	var pricedown = document.getElementById("pricedown");
	var goodsid = document.getElementById("goodsid");
	var urlNotice = "{php echo app_url('goods/list/notice')}";
	var urlNoticeRemove = "{php echo app_url('goods/list/noticeremove')}";
	
	if (User[goodsid.innerHTML + "notice"]) {
		pricedown.style.backgroundColor = "#fcc602";
		pricedown.innerHTML = "等待<br/>通知";
	}
	document.getElementById("returnBack").onclick = function () {
		location.href = "{php echo app_url('goods_list')}";
	}
	pricedown.onclick = function() {
		if (pricedown.style.backgroundColor != "rgb(252, 198, 2)" && confirm("确认降价提醒么")) {
			postAjax(goodsid.innerHTML, urlNotice);
			pricedown.style.backgroundColor = "#fcc602";
			pricedown.innerHTML = "等待<br/>通知";
			User[goodsid.innerHTML + "notice"] = '1';
			localStorage.setItem("user",JSON.stringify(User));
		}
		else if (pricedown.style.backgroundColor == "rgb(252, 198, 2)" && confirm("确认取消降价提醒么")) {
			postAjax(goodsid.innerHTML, urlNoticeRemove);
			pricedown.style.backgroundColor = "#6fbfd8";
			pricedown.innerHTML = "降价<br/>通知";
			delete User[goodsid.innerHTML + "notice"];
			localStorage.setItem("user",JSON.stringify(User));
		}
	}
	function isshow() {
		var canBuy = Number(document.getElementById("isshow").textContent);;
		return canBuy == 1 ? true : false;
	}
	//点击购物车跳出购物车
	buycart.onclick = function () {
	  cartDetails.style.setProperty( "height", "100%" );
	  cartDetails.style.setProperty( "opacity", "1" );
	  var str="";
	  for (var key in Buy) {
	    if (GuigeSelect[key] ===undefined) {
		  if (Buy[key]['num'] !=undefined){
		    str += buycartHtml(Buy[key]['img'], Buy[key]['price'], Buy[key]['num'], key, "");
		  }
	    }
		else{
		  var numArray =[];
		  var guigeArray = [];
		  for (var li in GuigeSelect[key]) {
			numArray.push(GuigeSelect[key][li]);
			guigeArray.push(li);			
		  }
		  if (Buy[key]['num'] !=undefined){
			str += buycartHtml(Buy[key]['img'], Buy[key]['price'],numArray, key,guigeArray.join(' '));
		  }
		}
	  }
	  buycartDetails.innerHTML =str;
	}
	
	//计算总数量并且调用计算总价格函数
	function totalNum() {
	  var totalnum = document.getElementById('totalnum');
	  var num=0;
	  for (var key in Buy) {
	   if (Buy[key]['num'] !== undefined) {
	    num += Buy[key]['num'];
	   }
	  }
	  totalnum.innerHTML = num;
	  if (num == 0) {
	    totalnum.style.setProperty('display', 'none');
	  }
	  else if (num > 0) {
	    totalnum.style.setProperty('display', 'block');
	  }
	  updataSum();
	}
	
	//保存session
	function saveSession() {
		sessionStorage.setItem("Buy", JSON.stringify(Buy));
		sessionStorage.setItem("GuigeSelect", JSON.stringify(GuigeSelect));
	}
	
	//选择规格属性，获取规格的数量
	function queryGuigestr(key) {
		var str = [];
		for (var a in GuigeSelect[key]) {
		  if (!(/.*Price/.test(a) || /.*Stock/.test(a) || /.*Weight/.test(a))){
			str.push(a);
		  }
		}
		return str;
	}

	//购物车减
	function minuscarNumber(ev) {
	  if (isPost){
	    isPost = false;
		var buynums = ev.parentNode.getElementsByClassName('buynum')[0];
		var index = ev.parentNode.getElementsByClassName('key')[0].innerHTML;
		var id = Buy[index]["id"] || document.getElementById("goodsid").textContent;
		var weight = sessionStorage.getItem("weight") ||  document.getElementById("goodsweight").textContent;
		var str = ev.parentNode.parentNode.getElementsByClassName('cartDetailGuige')[0].innerHTML;
		if (str === ''){
			if (postAjax(id, urlRemove, weight) || true ){
			  Buy[index]['num']--;
			  buynums.innerHTML = Buy[index]['num'];			  
			  if (Buy[index]['num']==0){			    
				ev.parentNode.parentNode.style.setProperty("display","none");
				delete Buy[index];
				buynums.innerHTML = 0;
			  }				  
			}
		} 
		else {
			weight = GuigeSelect[index][str+"Weight"];
			if (postAjax(id, urlRemove, weight, str) || true ){
			  Buy[index]['num']--;
			  GuigeSelect[index][str]--;			  
			  buynums.innerHTML = GuigeSelect[index][str];
			  if (GuigeSelect[index][str]==0){
				  ev.parentNode.parentNode.style.setProperty("display","none");
				  delete GuigeSelect[index][str];
				  delete GuigeSelect[index][str + 'Weight'];
				  delete GuigeSelect[index][str + 'Stock'];
				  delete GuigeSelect[index][str + 'Price'];
				  var n=0;
				  for (var key in GuigeSelect[index]){
					if (!( /.*Price/.test(key) || /.*Stock/.test(key) || /.*Weight/.test(key))){
					  n++;
					}					
				  }	
				  if (n==0) {					
					ev.parentNode.parentNode.parentNode.style.setProperty("display","none");
					delete GuigeSelect[index];
					delete Buy[index];
				  }
			  }
			}
		}
		totalNum();
	  }
	}
	
	//更新总价格
	function updataSum(){
		var sum = 0;
		saveSession();
		for (var key in Buy) {
			if (key in GuigeSelect) {
			  var jiage = queryGuigestr(key);
			  for (var i = 0; i< jiage.length; i++){
			    if (GuigeSelect[key][jiage[i]] !== undefined){
				  sum += GuigeSelect[key][jiage[i]] * GuigeSelect[key][jiage[i]+"Price"]; 
				}
			  }			 
			}
			else {
			  if ( Buy[key]['num'] !== undefined){
			    sum += Number(Buy[key]['num']) * Number(Buy[key]['price']);
				}
			}			
		}
		if (sum == 0){
			document.getElementById("sumprice").innerHTML = '￥ 0';
			return;
		}
		document.getElementById("sumprice").innerHTML = '共 ' + sum.toFixed(2) + ' 元';
	}
	
	//获得重量
	function getWeight(str) {
		var xhr = new XMLHttpRequest();
		xhr.open('post', urlweight, false);
		var formData = new FormData();
		formData.append("strname", str)
		xhr.send(formData);
		if ((xhr.status >=200 && xhr.status<300) || xhr.status ==304){
			Guige = JSON.parse(xhr.responseText);
			return true;
		}
		else{
			$.toast("无法获取重量");
			return false;
		}	
	} 
	
	//返回库存
	function checkstock(str) {
		return Number(Guige['stock']);
	}
	
	//返回重量
	function checkweight(str) {
		return Number(Guige['weight']);
	}
	
	//返回价格
	function checkprice(str) {
		return Number(Guige['productprice']);
	}
	
	//加载html页面
	function buycartHtml(imgstr, price, num, key, guige){
		var str = '';
		if (guige === ''){
			if (Number(num) > 0) {
				str = '<div class="tablerow">'
					+ '<div class="buyimg"><img src="' + imgstr + '"><\/div>'
					+ '<div class="buyprice">￥' + Number(price).toFixed(2) + '<\/div>'
					+ '<div class="buydes">'
					+ '<div class="buyplus" onclick="minuscarNumber(this)">-<\/div>'
					+ '<span class="key">' + key + '</span>'
					+ '<span class="cartDetailGuige">' + guige + '</span>'				
					+ '<div class="buynum">' + num + '<\/div>'
					+ '<div class="buyminus" onclick="pluscarNumber(this)">+<\/div>'
					+ '<\/div>'
					+ '<\/div>';
			}
		}
		else {
			var aa = guige.split(' ');
			var guigeArray = aa.filter(function(item, index, array) {
				return !( /.*Price/.test(item) || /.*Stock/.test(item) || /.*Weight/.test(item));
			});
			var guigeLen = guigeArray.length;
			var sum = 0;
			for (var b = 0; b<guigeLen; b++) {
				sum += Number(GuigeSelect[key][guigeArray[b]]);
			}
			if (sum > 0) {
				str += '<div class="tablerow"><div class="buyimg"><img src="' + imgstr + '"><\/div>';
				for ( var a = 0; a<guigeLen;a++) {
				  if (Number(GuigeSelect[key][guigeArray[a]])>0) {
					str += '<div class="tablerow">'
					+ '<div class="buyimg"><span class="cartDetailGuige" style="font-size:0.8em;color:hsl(354, 90%, 73%)">' + guigeArray[a] + '</span><\/div>'
					+ '<div class="buyprice">￥' + Number(GuigeSelect[key][guigeArray[a]+'Price']).toFixed(2) + '<\/div>'
					+ '<div class="buydes">'
					+ '<div class="buyplus" onclick="minuscarNumber(this)">-<\/div>'
					+ '<span class="key">' + key + '</span>'				
					+ '<div class="buynum">' + GuigeSelect[key][guigeArray[a]] + '<\/div>'
					+ '<div class="buyminus" onclick="pluscarNumber(this)">+<\/div>'
					+ '<\/div>'
					+ '<\/div>';
				  }
				}
				str += '<\/div>';
			}
		}			
		return str;
	}
	
	//购物车继续购买
	var continueBuy = document.getElementById( "continueBuy" );
	continueBuy.onclick = function () {
	  cartDetails.style.setProperty( "height", "0px" );
	  cartDetails.style.setProperty( "opacity", "0" );
	}
	
	//购物车一键清除
	function clearBuycart(){
	  if (isPost){
	    isPost = false;
		var minuses = document.getElementsByClassName('minus');		
		var xhr = new XMLHttpRequest();
		xhr.open('post', urlclear, true);
		xhr.send(null);
		xhr.onreadystatechange = function() {
			if (xhr.readyState ==4) {
				if ((xhr.status >=200 && xhr.status<300) || xhr.status ==304){
					isPost = true;
					if (Number(xhr.responseText)>0){
						buycartDetails.innerHTML = "";
						for (var key in Buy) {
							delete Buy[key];
						}
						for (var a in GuigeSelect) {
							delete GuigeSelect[a];
						}
						totalNum();
					}
					else{
						$.toast("清除失败");
					}
				}
				else {
					isPost = true;
					console.log("cuowu");
				}
			}
			else {
				isPost = true;
			}
		}
	  }
	}

	//购物车加 
	function pluscarNumber(ev) {
	  if (isPost){
	    isPost = false;
		var buynums = ev.parentNode.getElementsByClassName('buynum')[0];
		var index = ev.parentNode.getElementsByClassName('key')[0].innerHTML;
		var id = Buy[index]['id']|| document.getElementById("goodsid").textContent;
		//alert(id);
		var weight = sessionStorage.getItem("weight")|| document.getElementById("goodsweight").textContent;
		var str = ev.parentNode.parentNode.getElementsByClassName('cartDetailGuige')[0].innerHTML;		
		var kucunNumber = Number(sessionStorage.getItem("kucun"))|| Number(document.getElementById("goodsgnum").textContent );
		  if (str === ''){	
			if (Buy[index]['num'] < Buy[index]['kucun']) {
				if (postAjax(id, urladd, weight)|| true ){
				  Buy[index]['num']++;
				  buynums.innerHTML = Buy[index]['num'];
				}
				else {
					isPost = true;
				}
			}
			else {
				isPost = true;
				$.toast( "库存不足" );
			  }
		}			
		else {		
		  weight = GuigeSelect[index][str+"Weight"];
		  if (GuigeSelect[index][str] < GuigeSelect[index][str + 'Stock'] ) {		  
			if (postAjax(id, urladd, weight, str) || true ){
				Buy[index]['num']++;
				GuigeSelect[index][str]++;
				buynums.innerHTML = GuigeSelect[index][str];
			}
			else {
				isPost = true;
			}
		  }
		  else {
			isPost = true;
			$.toast( "库存不足" );
		  }
		}
		totalNum();
	  }
	}
	
	defaultLoad();
	//从session中获取已买的数据
	function defaultLoad() {
	  if (sessionStorage.getItem("Buy") !== 'undefined' && sessionStorage.getItem("Buy") !== null){
	    Buy = JSON.parse(sessionStorage.getItem("Buy"));
	  }
	  else {
		Buy = {};
	  }
	  if (sessionStorage.getItem("GuigeSelect") !== 'undefined' && sessionStorage.getItem("Buy") !== null){
	    GuigeSelect = JSON.parse(sessionStorage.getItem("GuigeSelect"));
	  }	
	  else {
		GuigeSelect = {};
	  }	  
	  totalNum();
	}
	
	//点击结算页面
	function Buycart(){
	  if (isPost){
		 if (document.getElementById('totalnum').innerHTML !== '0'){
			location.href = "{php echo app_url('order/shoporderconfirm')}";
		  }
	  }
	}
	
	//加减ajax
	function postAjax(id, url, weight, str){
		var formData = new FormData();
		formData.append('id', id);
		if (weight !== undefined) {
			formData.append("weight", weight);
		}else {
			formData.append("type", 2);
		}					
		if (str !==undefined){
		  formData.append("str",str);
		}
		var xhr = new XMLHttpRequest();
		xhr.open('post', url, true);
		xhr.send(formData);
		console.log(id + ' ' + weight + ' ' + str);
		xhr.onreadystatechange = function() {
			if (xhr.readyState ==4) {
			  if ((xhr.status >=200 && xhr.status<300) || xhr.status ==304){
				isPost = true;
				console.log(xhr.responseText);
				 return !!xhr.responseText;
			  }
			  else {
			    alert("由于网络或其他原因导致无法购买,请关闭浏览器重试");
				console.log("cuowu");
			  }
			}
		}
	}
	
	//回到首页 	
	gohome.onclick = function() {
	  sessionStorage.removeItem("position");
	}
	document.getElementById("productInfott").innerHTML=escapeHtml('{$goods['gdesc']}');	
	function bb(b){
		var many_limit = $("#many_limit").val();
	    var one_limit = $("#one_limit").val();
	    var times = $("#times").val();
	    many_limit = parseInt(many_limit);
		one_limit=parseInt(one_limit);
		times=parseInt(times);
		if(b==1){
			location.href = "{php echo app_url('order/orderconfirm',array('groupnum'=>1));}";
		}else{
			if(many_limit>=1){
	        		if(times >= many_limit){
		        		$.toast('单人购买总数为：'+many_limit+',您已购买'+times);
						return false;
		        	}
	        	}
			var nn = "{$goods['groupnum']}";
			location.href = "{php echo app_url('order/orderconfirm')}" + "&groupnum=" + nn;
		}
	}
	
	//点加有规格和没有规格，还有是否首页带来的数据
	function plusNumber(ev, str) {	
		var kucunNumber = Number(sessionStorage.getItem("kucun"))||document.getElementById("goodsgnum").textContent ;
		var i;
		if (sessionStorage.getItem("position") !== null) {
			i = sessionStorage.getItem("position").slice(-1);
		}	
		else {
			i = '999';
		}
	    var isguige = Number(sessionStorage.getItem("isGuige")) || document.getElementById("goodsguige").textContent ;
	    if (str !== undefined){
		  if (GuigeSelect==null) {
			GuigeSelect = {};		
		  }
	      if (GuigeSelect[i] === undefined){
		    GuigeSelect[i] = {};		
	       }
	      if (GuigeSelect[i][str] === undefined){
			GuigeSelect[i][str] = 0;
			if (getWeight(str)){
				GuigeSelect[i][str + 'Weight'] = checkweight(str);
				GuigeSelect[i][str + 'Stock'] = checkstock(str);
				GuigeSelect[i][str + 'Price'] = document.getElementById("option_oprice").textContent;
			}
		  }
	    }
	    if (Buy == null){
		   Buy = {};		  
		}
		if (Buy[i]===undefined){
			Buy[i]={};
			Buy[i]['img'] = sessionStorage.getItem('img') || document.getElementsByTagName("img")[0].src;
			Buy[i]['price'] = sessionStorage.getItem('price') || document.getElementById("goodsprice").innerHTML.slice(1);
			Buy[i]['id'] = sessionStorage.getItem("id") || document.getElementById("goodsid").textContent ;
			Buy[i]['weight'] = sessionStorage.getItem('weight') || document.getElementById("goodsweight").textContent ;
			Buy[i]['title'] = sessionStorage.getItem('title') || document.getElementById("goodstitle").innerHTML;
			Buy[i]['kucun'] = sessionStorage.getItem('kucun') || document.getElementById("goodsweight").textContent ;
	    }
	    if (Buy[i]['num']== undefined){
		    Buy[i]['num'] = 0;
	    }
		if (isguige>0){
			plusNumberOption(kucunNumber, ev, str);						
		}
		else {
		    plusNumberOption(kucunNumber, ev);
		}
	}
	
	//规格和没规格的加减
	function plusNumberOption( stock,ev, str) {
	  if (isPost){
	    isPost = false;
		var isguige = Number(sessionStorage.getItem("isGuige")) || Number(document.getElementById("goodsguige").textContent );
	    if (sessionStorage.getItem("position") !== null) {
			i = sessionStorage.getItem("position").slice(-1);
		}	
		else {
			i = '999';
		}
		var id = sessionStorage.getItem("id") || document.getElementById("goodsid").textContent ;
		if (str !== undefined){
		  var price = GuigeSelect[i][str + 'Price'];
		 }
		 else {
		   price = sessionStorage.getItem("price") || document.getElementById("goodsprice").textContent ;
		 }	   
		if (isguige <= 0){
			var weight = Buy[i]['weight'];
			if (postAjax(id, urladd, weight) || true ) {
			  if (stock - Buy[i]['num']>=1 && isshow()){
			    Buy[i]['num']++;
				flyimg.style.display = "block";
				drawFrame();
			  }
			  else {
				$.toast( "库存不足" );
				return;
			  }
			}
			else {
				isPost = true;
				console.log("error1");
			}
		  }
		  else {		    
			var weight = GuigeSelect[i][str + 'Weight'];
			GuigeSelect[i][str+'Price'] = price;
			if (postAjax(id, urladd, weight, str) || true ) {				
			  if (GuigeSelect[i][str + 'Stock'] < GuigeSelect[i][str] && isshow()){
				$.toast( "库存不足" );
				return;
			  }
			  else {
			    GuigeSelect[i][str]++;	
				Buy[i]['num']++;
				flyimg.style.display = "block";
				drawFrame();
			  }
			}
			else {
				isPost = true;
				console.log("error2");
			}
		  }
		totalNum();	
      }		
	}
	
    $("#num").blur(function(){
		var inputnum=$("#num").val();
		var marketprice = 0;
	    var productprice = 0;
		var options = {php echo json_encode($options)};
		var ret = option_selected();
	    var len = options.length;
	        for (var i = 0; i < len; i++) {
	            var o = options[i];
	            var ids = ret.all.join("_");
	            if (o.specs == ids) {
	                optionid = o.id;
	                stock = o.stock;
	                marketprice = o.marketprice;
	                productprice = o.productprice;
	                break;
	            }
	        }
	    if(marketprice==0){
	     	marketprice = "{php echo $goods['gprice']}";
	    }
		var goodsPrice=marketprice;
		var totalPrice = goodsPrice*inputnum;
		totalPrice = totalPrice.toFixed(2);
		$("#option_gprice").html(totalPrice);
	});
	
	$("#up").bind('click',function(){
		var num = $('#num').val();
			num = parseInt(num)+1;
			$('#num').val(num);
		var marketprice = 0;
	    var productprice = 0;
		var options = {php echo json_encode($options)};
		var ret = option_selected();
	    var len = options.length;
	        for (var i = 0; i < len; i++) {
	            var o = options[i];
	            var ids = ret.all.join("_");
	            if (o.specs == ids) {
	                optionid = o.id;
	                stock = o.stock;
	                marketprice = o.marketprice;
	                productprice = o.productprice;
	                break;
	            }
	        }
	     if(marketprice==0){
	     	marketprice = "{php echo $goods['gprice']}";
	     }
		 if(productprice==0){
	     	productprice = "{php echo $goods['oprice']}";
	     }
		var goodsPrice=marketprice;
		var inputnum=num;
		var totalPrice = goodsPrice*inputnum;
		totalPrice = totalPrice.toFixed(2);
		$("#option_gprice").html(totalPrice);
		$("#option_oprice").html((productprice*inputnum).toFixed(2));
	});
	
	$("#down").bind('click',function(){
		var num = $('#num').val();
		num = parseInt(num)-1;
		if(num<=0){
			num=1;
		}
		$('#num').val(num);
		var marketprice = 0;
	    var productprice = 0;
		var options = {php echo json_encode($options)};
		var ret = option_selected();
	    var len = options.length;
	        for (var i = 0; i < len; i++) {
	            var o = options[i];
	            var ids = ret.all.join("_");
	            if (o.specs == ids) {
	                optionid = o.id;
	                stock = o.stock;
	                marketprice = o.marketprice;
	                productprice = o.productprice;
	                break;
	            }
	        }
	     if(marketprice==0){
	     	marketprice = "{php echo $goods['gprice']}";
	     }
		  if(productprice==0){
	     	productprice = "{php echo $goods['oprice']}";
	     }
		var goodsPrice=marketprice;
		var inputnum=num;
		var totalPrice = goodsPrice*inputnum;
		totalPrice = totalPrice.toFixed(2);
		$("#option_gprice").html(totalPrice);
		$("#option_oprice").html((productprice*inputnum).toFixed(2));
	});

   $("#num2").blur(function(){
	var inputnum=$("#num2").val();
	var gp=$("#gn").val();
		gp = inputnum * gp;
		$("#option_price").html(gp);
	});
	
	$("#up2").bind('click',function(){
		var num = $('#num2').val();
			num = parseInt(num)+1;
			$('#num2').val(num);
		var gp=$("#gn").val();
			gp = num * gp;
			$("#option_price").html(gp);
	});
	
	$("#down2").bind('click',function(){
		var num = $('#num2').val();
		num = parseInt(num)-1;
		if(num<=0){
			num=1;
		}
		$('#num2').val(num);
		var gp=$("#gn").val();
			gp = num * gp;
			$("#option_price").html(gp);
	});

    var options = {php echo json_encode($options)};
    var specs = {php echo json_encode($specs)};
    var hasoption = {php echo $goods['hasoption'] == '1' ? 'true' : 'false'};
	
    var selected = [];
    function option_selected() {
        var ret = {
            no: "",
            all: []
        };
        if (!hasoption) {
            return ret;
        }
        $(".optionid").each(function () {
            ret.all.push($(this).val());
            if ($(this).val() == '') {
                ret.no = $(this).attr("title");
                return false;
            }
        })
        return ret;
    }
	
	function closechoose(){
		$('.footer').show();
        $('.good_choose_layer').fadeOut(100);
		$('.good_choose').fadeOut(100); 
    }

	function exchange(numb) {
		$('#div_nav .boxx .sp').removeClass('on');
		$('.section_specification').removeClass('on');
		$('.section_detail').removeClass('on');
		$('a#shangpin'+numb).addClass('on');
		if(numb==0) {
			$('.section_specification').addClass('on');
		}else{
			$('.section_detail').addClass('on');
		}
	}
	
	function showStores(obj){
        if($(obj).attr('show')=='1'){
            $(obj).next('div').slideUp(100);
            $(obj).removeAttr('show').find('i').removeClass('fa-angle-down').addClass('fa-angle-up');
        }else{
            $(obj).next('div').slideDown(100);
            $(obj).attr('show', '1').find('i').removeClass('fa-angle-up').addClass('fa-angle-down');
        }
    }
	
	function detailAnimation() {
		var i = 0, Animation = {},
		x = 0, y = 0;
		Animation.animationX = function () {
			i += 0.01;
			x = setX();
			return x;
		}
		Animation.animationY = function () {
			y = setY();
			return y;
		}
		function setX() {
			return ++x;
		}
	}
	
	function JietiTuan() {
		
	}
		var flyimg = document.getElementById("flyimg");
		
	flyimg.src = document.getElementsByTagName("img")[0].src;
	var imgRect = flyimg.getBoundingClientRect();
	var p1X = 20;
	var p1Y = 0;
	var imgX = imgRect.left;
	var imgY = imgRect.top;
	var buycartimg = document.getElementById("buycartimg");
	var buycartRect = buycartimg.getBoundingClientRect();
	var carX = buycartRect.left;
	var carY = buycartRect.top;
	deltaX = carX - imgX + 25;
	deltaY = carY - imgY;
	var middlePointX = p1X + deltaX / 2;
	var middlePointY = p1Y - 90;
	var start = 0;
	flyimg.style.display = "none";
	function drawFrame() {
		var requestID = requestAnimationFrame(drawFrame);
		var x = (1 - start) * (1 - start) * p1X + 2 * start * (1 - start) * middlePointX + start * start * deltaX;
		var y = (1 - start) * (1 - start) * p1Y + 2 * start * (1 - start) * middlePointY + start * start * deltaY;
		start += 0.05;
		flyimg.style.left = x +"px";
		flyimg.style.top = y+"px";	
		if (start > 1) {
			cancelAnimationFrame(requestID);
			start = 0;
			flyimg.style.left = "20px";
			flyimg.style.top = "0px";
			flyimg.style.display = "none";
		}
	}
	
</script>
{php include wl_template('common/footer');}